﻿@model Web.Models.SysUserModel

@{
    ViewBag.Title = "新增系统用户";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-12 col-md-12">
        @using (Html.BeginForm("Create", "SysUser", FormMethod.Post, new { id = "create-form", @class = "form-horizontal", role = "form" })) {
            @Html.Partial("_Notifications")
            <div class="panel">
                <div class="panel-heading">
                    <span><i class="fa fa-plus-square-o fa-fw"></i>@ViewBag.Title</span>
                </div>
                <div class="panel-body">
                    @Html.Partial("_CreateOrEdit", Model)
                </div>
                <div class="panel-footer">
                    <div class="form-group form-actions">
                        <div class="col-lg-offset-2 col-lg-6 col-sm-6">
                            <a class="btn btn-default  " href="~/SysUser/Index"><i class="fa fa-reply fa-fw"></i>返 回</a>
                            <button class="btn btn-primary" type="submit"><i class="fa fa-floppy-o fa-fw"></i>保 存</button>
                            <button class="btn btn-primary" type="button" onclick="saveSysuser();"><i class="fa fa-floppy-o fa-fw"></i>异步保存</button>
                            <button class="btn btn-primary" type="button" onclick="saveBatchSysuser();"><i class="fa fa-floppy-o fa-fw"></i>批量提交</button>
                        </div>
                    </div>
                </div>
            </div>
        }
    </div>
</div>
@section FootScript{

    <script type="text/javascript">
        //采用AJAX方式异步提交数据到服务
        function saveSysuser() {
            var data = new Object();
            data.UserName = $("#txtUserName").val();
            data.UserAccount = $("#txtUserAccount").val();
            data.Password = $("#txtPassword").val();
            data.DeptID = $("#drpDepts").val();
            data.Duty = $("#txtDuty").val();
            data.Telphone = $("#txtTelphone").val();
            data.Mobile = $("#txtMobile").val();
            data.Address = $("#txtAddress").val();

            $.post("@Url.Action("CreateAsynchronous")", data, function (result) {
                if (result.Succeed) alert(result.Message);
                if (!reuslt.Succeed) alert(result.Message);

            });
        }

        //采用AJAX方式批量提交数据到服务端
        function saveBatchSysuser() {
            var dataList = new Array();
            for (i = 0; i < 10; i++) {
                var Item = new Object();
                Item.UserName = $("#txtUserName").val();
                Item.UserAccount = $("#txtUserAccount").val();
                Item.Password = $("#txtPassword").val();
                Item.DeptID = $("#drpDepts").val();
                Item.Duty = $("#txtDuty").val();
                Item.Telphone = $("#txtTelphone").val();
                Item.Mobile = $("#txtMobile").val();
                Item.Address = $("#txtAddress").val();
                dataList.push(Item);
            }
            $.post("@Url.Action("BatchCreate")", { data: dataList }, function (result) {
                if (result.Succeed) alert(result.Message);
                if (!reuslt.Succeed) alert(result.Message);

            });
        }
    </script>
}
